import request from '@/utils/request'
const url = '/rpt/common/queryFromLine'
const method = 'post'
const printObj = {
  url: '/rpt/common/printFromLine',
  method
}
const mergeParams = function (code, obj) {
  return {
    templateClassificationCode: code,
    ...obj
  }
}

// -------------------采购统计----------------

export function getPurchaseTable(obj) {
  const data = mergeParams('purchase', obj)
  return request({ url, method, data })
}

export function exportPurchaseBook(data) {
  exportLines(data, 'purchase')
}

export function printPurchaseBook(obj) {
  const data = mergeParams('purchase', obj)
  return request({ ...printObj, data })
}

// -------------------采购退货统计----------------

export function getPurchaseReturnedTable(obj) {
  const data = mergeParams('purchaseReturned', obj)
  return request({ url, method, data })
}

export function exportPurchaseReturnedBook(data) {
  exportLines(data, 'purchaseReturned')
}

export function printPurchaseReturnedBook(obj) {
  const data = mergeParams('purchaseReturned', obj)
  return request({ ...printObj, data })
}

// -----------------销售统计--------------------

export function getSalesTable(obj) {
  const data = mergeParams('sales', obj)
  return request({ url, method, data })
}

export function exportSalesBook(data) {
  exportLines(data, 'sales')
}

export function printSalesBook(obj) {
  const data = mergeParams('sales', obj)
  return request({ ...printObj, data })
}

// -----------------销售退货统计--------------------

export function getSalesReturnedTable(obj) {
  const data = mergeParams('salesReturned', obj)
  return request({ url, method, data })
}

export function exportSalesReturnedBook(data) {
  exportLines(data, 'salesReturned')
}

export function printSalesReturnedBook(obj) {
  const data = mergeParams('salesReturned', obj)
  return request({ ...printObj, data })
}

// -------------------销售出库统计----------------

export function getOutboundOrderTable(obj) {
  const data = mergeParams('outboundOrder', obj)
  return request({ url, method, data })
}

export function exportOutboundOrderBook(data) {
  exportLines(data, 'outboundOrder')
}

export function printOutboundOrderBook(obj) {
  const data = mergeParams('outboundOrder', obj)
  return request({ ...printObj, data })
}

// -------------------销售退库统计----------------

export function getOutboundOrderReturnedTable(obj) {
  const data = mergeParams('outboundOrderReturned', obj)
  return request({ url, method, data })
}

export function exportOutboundOrderReturnedBook(data) {
  exportLines(data, 'outboundOrderReturned')
}

export function printOutboundOrderReturnedBook(obj) {
  const data = mergeParams('outboundOrderReturned', obj)
  return request({ ...printObj, data })
}

// -------------------预收统计----------------

export function getPresaleTable(obj) {
  const data = mergeParams('presale', obj)
  return request({ url, method, data })
}

export function exportPresaleBook(data) {
  exportLines(data, 'presale')
}

export function printPresaleBook(obj) {
  const data = mergeParams('presale', obj)
  return request({ ...printObj, data })
}

// -------------------预收退款统计----------------

export function getPresaleReturnedTable(obj) {
  const data = mergeParams('presaleReturned', obj)
  return request({ url, method, data })
}

export function exportPresaleReturnedBook(data) {
  exportLines(data, 'presaleReturned')
}

export function printPresaleReturnedBook(obj) {
  const data = mergeParams('presaleReturned', obj)
  return request({ ...printObj, data })
}

// -------------------入库统计----------------

export function getWarehousingEntryTable(obj) {
  const data = mergeParams('warehousingEntry', obj)
  return request({ url, method, data })
}

export function exportWarehousingEntryBook(data) {
  exportLines(data, 'warehousingEntry')
}

export function printWarehousingEntryBook(obj) {
  const data = mergeParams('warehousingEntry', obj)
  return request({ ...printObj, data })
}

// -------------------退货出库统计----------------

export function getWarehousingEntryReturnedTable(obj) {
  const data = mergeParams('warehousingEntryReturned', obj)
  return request({ url, method, data })
}

export function exportWarehousingEntryReturnedBook(data) {
  exportLines(data, 'warehousingEntryReturned')
}

export function printWarehousingEntryReturnedBook(obj) {
  const data = mergeParams('warehousingEntryReturned', obj)
  return request({ ...printObj, data })
}

// -------------------盘点----------------

export function getInventoryTable(obj) {
  const data = mergeParams('inventory', obj)
  return request({ url, method, data })
}

export function exportInventoryBook(data) {
  exportLines(data, 'inventory')
}

export function printInventoryBook(obj) {
  const data = mergeParams('inventory', obj)
  return request({ ...printObj, data })
}

// -------------------调拨----------------

export function getAllocationTable(obj) {
  const data = mergeParams('allocation', obj)
  return request({ url, method, data })
}

export function exportAllocationBook(data) {
  exportLines(data, 'allocation')
}

export function printAllocationBook(obj) {
  const data = mergeParams('allocation', obj)
  return request({ ...printObj, data })
}

// -------------------移库----------------

export function getMovementTable(obj) {
  const data = mergeParams('movement', obj)
  return request({ url, method, data })
}

export function exportMovementBook(data) {
  exportLines(data, 'movement')
}

export function printMovementBook(obj) {
  const data = mergeParams('movement', obj)
  return request({ ...printObj, data })
}

// -------------------收款----------------

export function getReceiptTable(obj) {
  const data = mergeParams('receipt', obj)
  return request({ url, method, data })
}

export function exportReceiptBook(data) {
  exportLines(data, 'receipt')
}

export function printReceiptBook(obj) {
  const data = mergeParams('receipt', obj)
  return request({ ...printObj, data })
}

// -------------------付款----------------

export function getPaymentTable(obj) {
  const data = mergeParams('payment', obj)
  return request({ url, method, data })
}

export function exportPaymentBook(data) {
  exportLines(data, 'payment')
}

export function printPaymentBook(obj) {
  const data = mergeParams('payment', obj)
  return request({ ...printObj, data })
}

// -------------------拜访----------------

export function getVisitTable(obj) {
  const data = mergeParams('visit', obj)
  return request({ url, method, data })
}

export function exportVisitBook(data) {
  exportLines(data, 'visit')
}

export function printVisitBook(obj) {
  const data = mergeParams('visit', obj)
  return request({ ...printObj, data })
}
// -------------------拜访----------------

export function getEveryDayTable(obj) {
  const data = mergeParams('everydayTotal', obj)
  return request({ url, method, data })
}

export function exportEveryDayBook(data) {
  exportLines(data, 'everydayTotal')
}

export function printEveryDayBook(obj) {
  const data = mergeParams('everydayTotal', obj)
  return request({ ...printObj, data })
}

// ---------------------毛利--------------------

export function getData3(data) {
  return request({
    url: '/gp/grossprofit/queryGrossProfitRotation',
    method: 'post',
    data
  })
}

export function getData4(data) {
  return request({
    url: '/gp/grossprofit/queryGrossProfitRotation',
    method: 'post',
    data
  })
}

// -------------------多维度毛利----------------

export function getGrossProfitTable(obj) {
  const data = mergeParams('grossProfit8', obj)
  return request({ url, method, data })
}

export function exportGrossProfitBook(data) {
  exportLines(data, 'grossProfit8')
}

export function printGrossProfitBook(obj) {
  const data = mergeParams('grossProfit8', obj)
  return request({ ...printObj, data })
}

// ------------------品类分项统计-------------

export function getGrossProfitTable6(obj) {
  const data = mergeParams('grossProfit6', obj)
  return request({ url, method, data })
}

export function exportGrossProfitBook6(data) {
  exportLines(data, 'grossProfit6')
}

export function printGrossProfitBook6(obj) {
  const data = mergeParams('grossProfit6', obj)
  return request({ ...printObj, data })
}

// ------------------模板列表------------------

export function getTemplateListByType(templateClassificationCode) {
  const data = {
    templateClassificationCode
  }
  return request({
    url: '/rpt/template/getTemplateList',
    method: 'post',
    data
  })
}

export function getColumnLabel(templateClassificationCode) {
  const data = {
    templateClassificationCode
  }
  return request({
    url: '/rpt/template/getAllSelectList',
    method: 'post',
    data
  })
}

function exportLines(data, templateClassificationCode) {
  const exurl = 'rpt/common/exportFromLine'
  const obj = {
    templateClassificationCode,
    ...data
  }
  var temp = document.createElement('form')
  temp.action = exurl
  temp.method = 'POST'
  temp.style.display = 'none'
  for (var x in obj) {
    var opt = document.createElement('textarea')
    opt.name = x
    opt.value = obj[x]
    temp.appendChild(opt)
  }
  document.body.appendChild(temp)
  temp.submit()
  return temp
}

// ----------------仓库统计------------------

export function getWarehousetable(data) {
  return request({
    url: '/ic/onhandQty/queryBookQtyList',
    method: 'post',
    data: data
  })
}

export function exportWarehouseBook(data) {
  var url = '/ic/onhandQty/exportAll'
  exportLines(data, url)
}

export function printWarehouseBook(data) {
  return request({
    url: '/ic/onhandQty/printAll',
    method: 'post',
    data: data
  })
}

// ----------------车辆统计------------------

export function getTrucktable(data) {
  return request({
    url: '/ic/truckQty/queryBookQtyList',
    method: 'post',
    data: data
  })
}

export function exportTruckBook(data) {
  var url = '/ic/truckQty/exportAll'
  exportLines(data, url)
}

export function printTruckBook(data) {
  return request({
    url: '/ic/truckQty/printAll',
    method: 'post',
    data: data
  })
}
